
/**
 * A pretty little class implementing the adoption rule
 */
public class Adaptation {
	private final int MONTH_DAYS = 20;
	private final int YEAR_DAYS = 220; 
	private Case newCase, mostSimilarCase; 
	
	
	public Adaptation(Case newCase, Case mostSimilarCase) {
		this.newCase = newCase; 
		this.mostSimilarCase = mostSimilarCase; 
	}
	
	
	/**
	 * Return the result in an object
	 * @return
	 */
	public Result fetchResult() {
		
		/*
		 * 
		 	8 person-hours = 1 person-day
			5 person-days = 1 person-week
			4 person-weeks = 1 person-month
			11 person-moths = 1 person-year
			
		 */
		int estimatedEffort = (int) Math.round(( (double) this.newCase.linesOfCode / this.mostSimilarCase.linesOfCode) * (int)this.mostSimilarCase.effortDays); 		
		int personHours = estimatedEffort*8 / this.newCase.teamSize; 
		int personDays = estimatedEffort / this.newCase.teamSize; 
		int personMonths = (estimatedEffort / MONTH_DAYS) / this.newCase.teamSize; 
		int personYears = (estimatedEffort / YEAR_DAYS) / this.newCase.teamSize; 
		
		
		return new Result(estimatedEffort, personHours, personDays, personMonths, personYears); 
	}
	
	/**
	 * Container class that contains the results of the adaptation rule
	 */
	static class Result {
		public int estimatedResult; 
		
		public int personHours; 
		public int personDays; 
		public int personMonths; 
		public int personYears; 
		
		public Result(int er, int ph, int pd, int pm, int py) {
			this.estimatedResult = er;
			this.personHours = ph; 
			this.personDays = pd; 
			this.personMonths = pm; 
			this.personYears = py; 			
		}
		
		public String toString() {
			return "Result [personHours=" + personHours + ", personDays="
					+ personDays + ", personMonths=" + personMonths
					+ ", personYears=" + personYears + "]";
		}
	}
	
}
